package tests.cases {
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import org.flexunit.Assert;
	
	import tests.cases.DefaultTestCase;
	
	public class TestGroupManagement extends DefaultTestCase {
		
		private var groupManagementService:RemoteObject;
		
		[Before]
		public function setUp():void {
			
			groupManagementService = new RemoteObject();
			groupManagementService.destination = "amfphp";
			groupManagementService.source = "GroupManagementService";
		}
		
		[After]
		public function tearDown():void {
			
			groupManagementService = null;
		}
		
		// ----------------------------------------------------------------
		// TEST GROUP PROFILE
		// ----------------------------------------------------------------
		[Test(async,order=1)]
		public function testGetGroupProfile():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				groupUID: "group001"
			};
			
			var token:AsyncToken = groupManagementService.getGroupProfile(argsVO.sessionID, argsVO.groupUID);
			runAsyncTest(token, argsVO, handleGetGroupProfile);
		}
		
		private function handleGetGroupProfile(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			
			Assert.assertNotNull(message.result.modules);
			Assert.assertNotNull(message.result.members);
			Assert.assertNotNull(message.result.sponsors);
			Assert.assertNotNull(message.result.blogPosts);
			Assert.assertNotNull(message.result.forumPosts);
			Assert.assertNotNull(message.result.events);
		}
		
		// ----------------------------------------------------------------
		// TEST USER LIST
		// ----------------------------------------------------------------
		[Test(async,order=2)]
		public function testGetGroupUsers():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				groupUID: "group001"
			};
			
			var token:AsyncToken = groupManagementService.getGroupUsers(argsVO.sessionID, argsVO.groupUID);
			runAsyncTest(token, argsVO, handleGetUserList);
		}
		
		private function handleGetUserList(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			Assert.assertTrue((message.result.length > 0));
		}
		
		// ----------------------------------------------------------------
		// TEST BAN USER
		// ----------------------------------------------------------------
		[Test(async,order=3)]
		public function testBanUser():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001",
				groupUID: "group001"
			};
			
			var token:AsyncToken = groupManagementService.banUser(argsVO.sessionID, argsVO.userUID, argsVO.groupUID);
			runAsyncTest(token, argsVO, handleBanUser);
		}
		
		private function handleBanUser(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			Assert.assertEquals("user001", message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST UNBAN USER
		// ----------------------------------------------------------------
		[Test(async,order=4)]
		public function testUnbanUser():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001",
				groupUID: "group001"
			};
			
			var token:AsyncToken = groupManagementService.unbanUser(argsVO.sessionID, argsVO.userUID, argsVO.groupUID);
			runAsyncTest(token, argsVO, handleUnbanUser);
		}
		
		private function handleUnbanUser(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			Assert.assertEquals("user001", message.result);
		}
	}
}